<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Blog后台管理</title>
    <!--    <link rel="stylesheet" href="css/semantic.min.css">-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">

</head>
<body>
<!--导航-->
<nav class="ui inverted attached segment m-padded-tb-mini m-shadown-small" th:replace="admin/_fragments :: menu(1)">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui header teal item">后台管理</h2>
            <a href="#" class="active am-item item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <div class="right m-item m-mobile-hide menu">
                <div class="ui dropdown item">
                    <div class="text">
                        <img src="../../static/images/touxiang.jpg" th:src="@{/images/touxiang.jpg}" alt="" class="ui avatar image">
                        周纯彬
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" th:href="@{/admin/logout}" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show ">
        <i class="sidebar icon"></i>
    </a>
</nav>
<!--二级导航-->
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="release.html" th:href="@{/admin/release}" class="item">发布</a>
            <a href="blogs.html" th:href="@{/admin/blogs}" class="teal active item">列表</a>
        </div>
    </div>
</div>
<!--=========================中间内容==============================-->

<div class="m-padded-tb-larges m-container-small">
    <div class="ui container">
        <div class="ui secondary segment form">
          <input type="hidden" name="page">
            <div class="inline fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field">
                    <div class="ui selection dropdown">
                        <input type="hidden" name="typeId">
                        <i class="dropdown icon"></i>
                        <div class="default text">分类</div>
                        <div class="menu">
                            <div th:each="type : ${types}" class="item" th:data-value="${type.id}" th:text="${type.name}">错误日志</div> <!-- data-value="1"-->
                            <div class="item inverted" ></div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recomnmend" name="recommend">
                        <label for="recomnmend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <button type="button" id="search-btn" class="ui mini teal basic button"><i class="search icon"></i></button>
                </div>
            </div>
        </div>
        <div id="table-container">
            <table th:fragment="blogList" class="ui table celled center aligned">
                <thead>
                <tr>
                    <th>/</th>
                    <th>id</th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>发布</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog,iterStat : ${blogpageInfo.list}">
                    <td th:text="${iterStat.count}" >1</td>
                    <td th:text="${blog.id}" >1</td>
                    <td th:text="${blog.title}">可以练习清单</td>
                    <td th:text="${blog.type.name}">认识升级</td>
                    <td th:text="${blog.recommend}?'是':'否'">是</td>
                    <td th:text="${blog.published}?'发布':'草稿'">是</td>
                    <td th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd hh-mm-ss') }">2021-09-01 10:18</td>
                    <td>
                        <a href="#"  th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui font-blue mini button"><span style="color: white">编辑</span></a><!---->
                        <a href="#" id="delBtn"   class="ui remove red mini button"><span style="color: white">删除</span></a>
                    </td><!--th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}"-->
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <th colspan="8">
                        <div class="ui pagination mini menu" th:classappend="${blogpageInfo.getPages()==1}?'m-dispalty'" >
                            <a onclick="page(this)" id="prepn"   th:attr="data-page=${blogpageInfo.pageNum}-1" th:classappend="${blogpageInfo.isFirstPage}?'m-dispalty'" class="item pagen">上一页</a>
                            <a onclick="page(this)" id="nextpn"  th:attr="data-page=${blogpageInfo.pageNum}+1" th:classappend="${blogpageInfo.isLastPage}?'m-dispalty'" class="item pagen">下一页</a>
                        </div><!--th:href="@{/admin/blogs(pn=${blogpageInfo.pageNum}+1)}"-->
                        <a href="#" th:href="@{/admin/release}"  class="ui mini right floated teal basic button">新增</a>
                    </th>
                </tr>
                </tfoot>
                <div id="divpn" th:text="${blogpageInfo.getPageNum()}" style="display: none!important;"></div>
            </table>

            <!--添加结果提示-->
            <div class="ui success message" th:unless="${#strings.isEmpty(BlogMessage)}">
                <i class="close icon"></i>
                <h2 class="header">提示：</h2>
                <p th:text="${BlogMessage}" >恭喜，操作成功</p>
            </div>


        </div>

    </div>
</div>
<br>
<!--========================底部footer===============================-->
<!---->
<footer class="ui inverted vertical segment m-padded-tb-big" th:replace="admin/_fragments :: footer">
    <div class="ui center aligned container">
        <div class="ui stackable inverted divided grid">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../../static/images/meWechat.jpg" th:src="@{/images/meWechat.jpg}" class="ui rounded image" alt="" style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="four wide column">
                <h4 class="ui inverted header  m-font-spaced" style="font-weight: normal">最新博客</h4>
                <div class="ui inverted link list m-font-thin">
                    <a href="#" class="item">笔记01</a>
                    <a href="#" class="item">笔记01</a>
                    <a href="#" class="item">笔记01</a>
                </div>
            </div>

            <div class="five wide column">
                <h4 class="ui inverted header" style="font-weight: normal">Blog介绍</h4>
                <p class="m-font-thin m-font-spaced m-opacity-mini ">修炼一途，乃窃阴阳，夺造化，转涅槃，握生死，掌轮回。 武之极，破苍穹，动乾坤！</p>
            </div>
            <div class="four wide column">
                <h4 class="ui inverted header  m-font-spaced" style="font-weight: normal">联系我</h4>
                <div class="ui inverted  list" style="text-align: left;margin-left: 30px">
                    <div class="item">
                        <img src="../../static/images/qq.png" th:src="@{/images/qq.png}" style="width: 20px">
                        <span class="m-font-thin m-opacity-mini"
                              style="font-size: 14px">&nbsp;&nbsp;QQ：2251073096</span>
                    </div>
                    <div class="item">
                        <img src="../../static/images/email.png" th:src="@{/images/email.png}" style="width: 18px">
                        <span class="m-opacity-mini" style="font-size: 14px">&nbsp;&nbsp;Eamil：2251073096@qq.com</span>
                    </div>
                </div>
            </div>
        </div>

        <div class="ui inverted section divider"></div>
        <p class="m-font-thin m-font-spaced m-opacity-tiny" style="font-size: 13px">Copyright © 2021 - 2022 ZhouChB All
            Rights Reserved V.1.0</p>
    </div>
</footer>
<script src="../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script src="../../static/js/semantic.min.js" th:src="@{/js/semantic.min.js}"></script>
<script src="../../static/js/my.js" th:src="@{/js/my.js}"></script>

<script>
    $(function(){
        $('#pa').hover(function(){
            var f2 = $(this).attr('data-page');
            console.log(f2);
        });})

    //分页
    function page(obj) {
   //     var pn = "?pn="+data("pn")
        $("[name='page']").val($(obj).data("page"));
        loaddata();
    }
//搜索
    $("#search-btn").click(function () {
        $("[name='page']").val(0);
        loaddata();
    });

    function loaddata() {
        //var f2 ='?pn='+ $("#nextpn").attr('data-page');
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
            title : $("[name='title']").val(),
            typeId : $("[name='typeId']").val(),
            recommend : $("[name='recommend']").prop('checked'),
            page : $("[name='page']").val(),
             pn : $("[name='page']").val()
        });
    }

    /*关闭消息提示*/
    $('.message .close').on('click',function () {
        $(this)
            .closest('.message')
            .transition('fade');
    });

    //单个删除
    $(document).on("click", "#delBtn", function () {
        //    找tr标签下的第三个td标签，对应的就是员工名字
        var pn = document.getElementById("divpn").innerText
        var id = $(this).parents("td").parents("tr").find("td:eq(1)").text();
        var title = $(this).parents("td").parents("tr").find("td:eq(2)").text();
        //弹出确认框，点击确认就删除
       if(confirm("确认删除 [" + title + "] 吗？")){
            //    确认，发送ajax请求删除
            $.ajax({
                url:"/admin/blogs/delete/"+id,
                type:"GET",
                success:function (res) {
                   // window.location.reload();
                    window.open("/admin/blogs?pn="+pn)
                    console.log("删除成功");
                }
            })
        }
    });


        /*页眉三杠*/
        $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });


</script>
<!--<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"/>-->
<!--<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>-->
</body>
</html>